package com.flats.service.transactional;

import com.flats.model.dao.Dao;
import com.flats.model.entity.Address;
import com.flats.service.AddressService;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Transactional
public class TransactionalAddressService implements AddressService {
    private Dao<Address> addressDao;

    public void setAddressDao(Dao<Address> addressDao) {
        this.addressDao = addressDao;
    }


    @Override
    @Transactional
    public Serializable saveOrUpdate(Address persistent) {
        Serializable id = addressDao.saveOrUpdate(persistent);
        return id;
    }

    @Override
    @Transactional
    public void delete(Long id) {
        addressDao.delete(id);
    }

    @Override
    @Transactional
    public void delete(Address persistent) {
       addressDao.delete(persistent);
    }

    @Override
    @Transactional
    public Address get(Long id) {
       return addressDao.get(id);
    }

    @Override
    @Transactional
    public List<Address> getAll() {
        return addressDao.getAll();
    }

}
